//////////////////////////////////////////////////////////////////////////////
//
//  Created by Philip Mulcahy on 15/01/2013.
//  Copyright (c) 2012 Philip Mulcahy. All rights reserved.
//
//  This file is part of the note-recog library.
//
//  note-recog is free software: you can redistribute it and/or modify
//  it under the terms of version 3 of the GNU Lesser General Public License 
//  as published by the Free Software Foundation.
//
//  note-recog is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with note-recog. If not, see <http://www.gnu.org/licenses/>.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef note_recog_Frame_h
#define note_recog_Frame_h

#include <iostream>
#include <vector>
#include "Spectrum.h"

class Frame
{  
public:
    typedef std::vector<short> TimeDomain;
    
    Frame(const TimeDomain& timeDomain, float timestamp, float samplingFreq)
    : _time_domain(timeDomain),
      _spectrum(Spectrum::fromTimeDomain(timeDomain, samplingFreq)),
      _timestamp(timestamp)
    {}
    
    Frame(const Frame& rhs)
    : _time_domain(rhs._time_domain),
      _spectrum(rhs._spectrum),
      _timestamp(rhs._timestamp) {}
    
    ~Frame(){};
private:
    Frame& operator=(const Frame&); // not implemented
public:
    const Spectrum& spectrum() const {return _spectrum;}
    const float startTimestamp() const {return _timestamp;}
    const float endTimestamp() const {return _timestamp + (_time_domain.size() / _spectrum.samplingFreq());}
    const TimeDomain& time_domain() const {return _time_domain;}
    std::vector<Frame> halves() const;
private:
    const Spectrum _spectrum;
    const float _timestamp;
    const TimeDomain _time_domain;
};

std::ostream& operator<<(std::ostream&, const Frame&);

#endif
